package com.xcc.eureka.client.control;

import com.xcc.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @outhor Ren
 * @create 2019-03-01 22:45
 * 描述:
 */

/**
 * RefreshScope 自定义配置文件属性更新
 */
@RestController
@RequestMapping("/test")
@RefreshScope
public class TestRestFul {

    @Autowired
    private HttpServletRequest mRequest;

    @Value("${server.port}")
    private int port;

    @Value("${serverPort}")
    private int serverPort;

    @GetMapping("/getNumber")
    public String test(String num) {
        System.out.println("配置文件变量： " + serverPort);
        System.out.println("header: " + mRequest.getHeader("test"));
        System.out.println("访问端口: " + port);
        return "获取传入值: " + num;
    }

    @PostMapping(value = "/getObj")
    @ResponseBody
    public User getObj(@RequestBody User user) {
        return user;
    }
}
